//
//  Hello World client in go
//  Connects REQ socket to tcp://localhost:5555
//  Sends "Hello" to server, expects "World" back
//
package main

import (
	"fmt"
	"os"
	"zmq"
)

func zmq_main() os.Error {
	context, err := zmq.Init(1)
	if err != nil {
		return err
	}
	defer context.Close()

	socket, err := context.Socket(zmq.REQ)
	if err != nil {
		return err
	}
	defer socket.Close()

	fmt.Println("Connecting to hello world server...")
	err = socket.Connect("tcp://localhost:5555")
	if err != nil {
		return err
	}

	for i := 0; i < 10; i++ {
		fmt.Println("Sending hello", i, "...")
		socket.Send([]byte("Hello"), 0)

		reply, err := socket.Recv(0)
		if err != nil {
			return err
		}
		fmt.Printf("Received %d %s\n", i, reply)
	}

	return nil
}

func main() {
	fmt.Println("Hello World client!")
	err := zmq_main()
	if err != nil {
		fmt.Println(err)
	}
}